"""
约瑟夫环问题
"""


def main():
    persons = [True]*30
    index, num, counter = 0, 0, 0
    while counter < 15:
        if persons[index]:
            num += 1
            if num == 9:
                persons[index] = False
                counter += 1
                num = 0
        index += 1
        index %= 30
    for pos, person in enumerate(persons):
        print(pos,'基' if person else '非')


if __name__ == '__main__':
    main()
        
